package it.tukano.swingdeco.event;

import java.awt.Component;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import javax.swing.SwingUtilities;

/**
 * A listener for a lot of events
 * @author pgi
 */
public class InputAdapter implements MouseListener, MouseMotionListener, MouseWheelListener, KeyListener {

    /**
     * Instance initializer
     */
    public InputAdapter() {
    }

    /**
     * Installs this listener in the given target (calling the addXYZListener methods)
     * @param target where to install this listener
     */
    public void installListeners(Component target) {
        target.addMouseListener(this);
        target.addMouseMotionListener(this);
        target.addMouseWheelListener(this);
        target.addKeyListener(this);
    }

    /**
     * Uninstall this listener from the given target (calling the removeXYZListener methods)
     * @param target where to remove this listener from
     */
    public void uninstallListeners(Component target) {
        target.removeMouseListener(this);
        target.removeMouseMotionListener(this);
        target.removeMouseWheelListener(this);
        target.removeKeyListener(this);
    }

    public void mouseClicked(MouseEvent e) {
        if(SwingUtilities.isLeftMouseButton(e)) onLeftMouseClicked(new MouseEventExt(e));
        else if(SwingUtilities.isRightMouseButton(e)) onRightMouseClicked(new MouseEventExt(e));
        else if(SwingUtilities.isMiddleMouseButton(e)) onMiddleMouseClicked(new MouseEventExt(e));
        else onUnknownMouseClicked(new MouseEventExt(e));
    }

    public void mousePressed(MouseEvent e) {
        if(SwingUtilities.isLeftMouseButton(e)) onLeftMousePressed(new MouseEventExt(e));
        else if(SwingUtilities.isRightMouseButton(e)) onRightMousePressed(new MouseEventExt(e));
        else if(SwingUtilities.isMiddleMouseButton(e)) onMiddleMousePressed(new MouseEventExt(e));
        else onUnknownMousePressed(new MouseEventExt(e));
    }

    public void mouseReleased(MouseEvent e) {
        if(SwingUtilities.isLeftMouseButton(e)) onLeftMouseReleased(new MouseEventExt(e));
        else if(SwingUtilities.isRightMouseButton(e)) onRightMouseReleased(new MouseEventExt(e));
        else if(SwingUtilities.isMiddleMouseButton(e)) onMiddleMouseReleased(new MouseEventExt(e));
        else onUnknownMouseReleased(new MouseEventExt(e));
    }

    public void mouseEntered(MouseEvent e) {

    }

    public void mouseExited(MouseEvent e) {

    }

    public void mouseDragged(MouseEvent e) {
        if(SwingUtilities.isLeftMouseButton(e)) onLeftMouseDragged(new MouseEventExt(e));
        else if(SwingUtilities.isRightMouseButton(e)) onRightMouseDragged(new MouseEventExt(e));
        else if(SwingUtilities.isMiddleMouseButton(e)) onMiddleMouseDragged(new MouseEventExt(e));
        else onUnknownMouseDragged(new MouseEventExt(e));
    }

    public void mouseMoved(MouseEvent e) {

    }

    public void mouseWheelMoved(MouseWheelEvent e) {

    }

    public void keyTyped(KeyEvent e) {

    }

    public void keyPressed(KeyEvent e) {

    }

    public void keyReleased(KeyEvent e) {

    }

    protected void onLeftMouseClicked(MouseEventExt e) {
    }

    protected void onRightMouseClicked(MouseEventExt e) {
    }

    protected void onMiddleMouseClicked(MouseEventExt e) {

    }

    protected void onUnknownMouseClicked(MouseEventExt e) {

    }

    protected void onLeftMousePressed(MouseEventExt e) {

    }

    protected void onRightMousePressed(MouseEventExt e) {

    }

    protected void onMiddleMousePressed(MouseEventExt e) {

    }

    protected void onUnknownMousePressed(MouseEventExt e) {

    }

    protected void onLeftMouseReleased(MouseEventExt e) {
        
    }

    protected void onRightMouseReleased(MouseEventExt e) {

    }

    protected void onMiddleMouseReleased(MouseEventExt e) {

    }

    protected void onUnknownMouseReleased(MouseEventExt e) {

    }

    protected void onLeftMouseDragged(MouseEventExt e) {

    }

    protected void onRightMouseDragged(MouseEventExt e) {

    }

    protected void onMiddleMouseDragged(MouseEventExt e) {

    }

    protected void onUnknownMouseDragged(MouseEventExt e) {

    }
}
